

<style type="text/css">
	


</style>

<body>


<div class="box" id='login-box'>
	<div class="form-wrapper">
		<h3 class="lead">LOG IN</h3>
		<hr>
	
		<form id='login-form' method='POST' action = 'ajax/formlogin'>	
			<label id='login-error-label'><?php if (isset($error)) echo $error ?></label><br />			
			<div class="field">
				<input type="text" name="user-input" class="text input" id="user-input" placeholder="YourEmail @aubg.bg">
				<br><br>
			</div>
			<div class="field">
				<input type="password" class="password input" id="password-input" name="password-input" placeholder="Password">
				<br><br>
			</div>

			<div class='row' >
				<div id='submit-login' class="medium primary btn icon-right icon-right-open-big twelve columns">
					<button type='submit'>Log In</button>
				</div>
			</div>
			<div class='row'>
				<div id='submit-forgotten' class='six columns'>
					<a href="#">Forgot password?</a>
				</div>
			</div>
		</form>		


	</div>
</div>
<script type="text/javascript">
	
$(function(){
	$('#submit-login').on("click", submitted);	
	$('#close-button').on("click", closed);	
});
	function closed(e){
		$('#login-form').css('display', 'none');	
		e.preventDefault();
	}
	function submitted(e){
		e.preventDefault();
	
//		document.getElementById('loading').style.display = 'block';
//		document.getElementById('loading').innerHTML = document.getElementById('loading').innerHTML;

		
		var user = $('#user-input').html;
		var password = $('#password-input').html;
		var login_array = $('#login-form').serialize();
		console.log(login_array);
		
		//$(this).css('display', 'none');
		$.ajax({
			beforeSend: function () {   
				//var loading = $('#loading');
				$('#submit-login').css('display', 'none');
				//loading.css('display', 'block');
	        },
			url: 'login/ajaxlogin',
			type: 'POST',
			data: login_array,
			success: function(data){
				
				msg = $.parseJSON(data);				
				if (msg.message == 'success'){
					location.reload();	
				}
				else{
					var fail = 'Your username and password are incorrect';
					$('#login-error-label').css('display', 'block').text(msg.message); 
					$('#submit-login').css('display', 'block');
					//loading.css('display', 'none');	
				}
				
				
			}, 
			error: function(data){
				alert('XHR error');	
				$('#submit-login').css('display', 'block');	
				//loading.css('display', 'none');
			}
		});
		
		e.preventDefault();
	}

</script>
